<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
</html>
<script>
  function sum(t, j) {
    var a = 0; //鸡

    var b = 0; //兔

    for (var a = 0; a < t; a++) {
      b = t - a;

      if (2 * a + 4 * b == j) {
        alert("鸡有" + a + "只，兔有" + b + "只");

        return;
      }
    }

    alert("输入有误，不能计算出鸡和兔的数量");
  }

  sum(2, 6);
</script>
